package view.diaLogView;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.administrator.text.R;

import util.NetWorkstateUtil;


/**
 * Created by Administrator on 2016/6/30.
 *  联网中
 */
public class NetworkingDialog extends Dialog{
    private NetworkingDialog mNetworkingDialog;
    private Context mContext;
    private boolean mState = true;
    private TextView mTvShowName,mTVName;
    private FrameLayout mFrameLayout;

    @Override public void show() {
        Window window = getWindow();
        window.setGravity(Gravity.BOTTOM);
        super.show();
    }

    public NetworkingDialog(Context context) {
        super(context, R.style.upoad_dialog);
        this.mContext = context;
        mNetworkingDialog = this;
    }

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    private void init() {

        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.width = mContext.getResources().getDisplayMetrics().widthPixels;
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View mView = inflater.inflate(R.layout.networking_dialog, null);
        ImageView imageView = (ImageView)mView.findViewById(R.id.iv_networkingfinish_dlog);   //取消
        mTvShowName = (TextView)mView.findViewById(R.id.tv_networkingshowName_dlog); //显示次数
        mTVName = (TextView) mView.findViewById(R.id.tv_networkingName_dlog);
        mFrameLayout = (FrameLayout)mView.findViewById(R.id.fl_networking_dlog);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mNetworkingDialog.dismiss();
                mState = false;
                NetWorkstateUtil.getInstance().setmNetWorkstateFail(0);
            }
        });


        setContentView(mView, params);
    }

    /**
     * 显示次数和提示信息
     */
   public void showTVName(String name,String name1){
       mFrameLayout.setVisibility(View.VISIBLE);
       mTvShowName.setText(name);
       mTVName.setText(name1);
   }

    /**
     * 关闭显示
     */
   public void diaLogDismiss(){
          mNetworkingDialog.dismiss();
          NetWorkstateUtil.getInstance().setmNetWorkstateFail(0);
   }

    /**
     * 显示状态
     */
    public boolean showShate(){
        return mState;

    }

    /**
     * 改变其状态
     */
    public void setShate(boolean state){
             mState = state;
    }

    /**
     * 提示信息
     */
    public void getShowName(String show){
        mFrameLayout.setVisibility(View.GONE);
        mTVName.setText(show);
    }

}
